<?php
/**
 * @package nuo
 * @author   Nam Nguyen <nam.ngvan@gmail.com>
 * @version  1.0
 * @since    Apr 17, 2013
 */
class Nuo_Controller
{
	/**
	 * Constructor
	 */
	public function __construct()
	{
		$this -> init();
	}

	/**
	 * Initialized method
	 * @access  public
	 * @return  void
	 */
	public function init()
	{
		/**
		 * code here
		 */
	}

	/**
	 * Get module name of class, in lower case format.
	 * @access   public
	 * @return   string
	 */
	function getModule()
	{
		$class = strtolower(get_class($this));
		return substr($class, 0, strpos($class, '_'));
	}

	/**
	 * Get associate script of this class
	 * @access   public
	 * @param    string
	 */
	function getScript()
	{
		$class = strtolower(get_class($this));

		list($k1, $k2) = explode('_', $class, 2);

		$script = $k1 . '/view/' . str_replace('_', '/', $k2);
	}

	/**
	 * Render data to associate views scripts, this method is caleed to any object
	 * implement renderable
	 * @param    array   $data  Optinal
	 * @return   string  xhtml string
	 */
	public function render($data = array())
	{
		list($k1, $k2) = explode('_', strtolower(get_class($this)), 2);

		$script = $k1 . '/view/' . str_replace('_', '/', $k2);

		return Nuo::getView()->render($script, $data);
	}

	/**
	 * Get string code of this element
	 * @access   public
	 * @return   string
	 */
	public function getCode()
	{
		$class = strtolower(get_class($this));
		return $k1 . '.' . $k2;
	}

}
